import * as api from '@/services/SupplyPlanMgr';

const Model = {
  namespace: 'OperatingPlanVersions',
  state: {
    data: [],
  },
  effects: {
    *fetch({ payload, callback }, { call, put }) {
      const response = yield call(api.versionListUsingGET, payload);
      if (response && response.data) {
        yield put({
          type: 'save',
          payload: response.data ? response : { data: [] },
        });
      }

      if (callback) callback(response && response.data ? response.data : []);
    },
  },
  reducers: {
    save(state, action) {
      return {
        ...state,
        data: action.payload.data,
      };
    },
  },
};
export default Model;
